#include "gd32f4xx.h"
#include "main.h"
#include "systick.h"
#include "adc.h"
#include "gpio.h"
#include "spi.h"
#include "tim.h"
#include "usb_device.h"
#include "uart.h"

#include "freertos_vars.h"
#include "cmsis_os.h"


void MX_FREERTOS_Init(void);

void early_start_checks(void) {
    
}

/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* configure systick */
    
    nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
    systick_config();
    GPIO_Init();
    
    SPI2_Init();    //driver
    ADC0_Init();   
    ADC1_Init();    
    ADC2_Init();

    CAN0_Init();

    TIM0_Init();    //M0
    TIM7_Init();    //M1
    TIM2_Init();    //encoder0
    TIM3_Init();    //encoder1
    TIM4_Init();    //pwm ic
    TIM8_Init();    //pwm ic
    TIM12_Init();   //log time
    TIM13_Init();   //timebase

    UART3_Init();
    USB_DEVICE_Init();
    /* Call init function for freertos objects (in freertos.c) */
    MX_FREERTOS_Init();

    /* Start scheduler */
    osKernelStart();

    while(1){
        /* if (USBD_CONFIGURED == cdc_acm.dev.cur_status) {
            if (0U == cdc_acm_check_ready(&cdc_acm)) {
                cdc_acm_data_receive(&cdc_acm);
            } else {
                cdc_acm_data_send(&cdc_acm);
            }
        } */
    }
}
